<!-- <template>
   <div> test111
</div></template>

<script>
    export default {}
	
	
	// 获取当前版本号
	getNativeVersion(){
	    let that = this;
	    plus.runtime.getProperty(plus.runtime.appid, function(inf){
	        that.nativeVersion = inf.version;
	        that.checkUpdate(inf.version);
	        localStorage.setItem("nativeVersion", inf.version);
	    });
	},
	// 检查更新
	checkUpdate(nativeVersion){
	    let that = this;
	    const checkUrl = "你的更新地址?date="+new Date();
	    var xhr = new XMLHttpRequest();
	    xhr.onreadystatechange = function(){
	        if (xhr.readyState === 4) {
	            if(xhr.status === 200){
	                let responseObj = JSON.parse(xhr.responseText);
	                let serverVersion = responseObj.version;
	                if(responseObj.update === "yes" && nativeVersion < serverVersion){
	                    that.downloadApk(responseObj.url);
	                }
	            }
	        }
	    };
	    xhr.open('GET',checkUrl);
	    xhr.send();
	},
	// 下载apk文件
	downloadApk(url){
	    let that = this;
	    plus.downloader.createDownload( url , {filename: "_doc/update/"}, function(d, status){
	        if ( status === 200 ) {
	            // 安装apk资源包
	            that.installFlag = true;
	            that.path = d.filename;
	        }
	    }).start();
	},
	// 安装apk
	installApk(){
	    this.installFlag = false;
	    plus.nativeUI.showWaiting("安装更新");
	    plus.runtime.install(this.path,{},function(){
	        plus.nativeUI.closeWaiting();
	        plus.nativeUI.alert("更新完成！",function(){
	            //  更新完成后重启应用
	            plus.runtime.restart();
	        });
	    },function(e){
	        plus.nativeUI.closeWaiting();
	        plus.nativeUI.toast("安装更新失败！");
	    });
	}
</script>

 -->
